﻿
$.CAlert = {
    Alert: function (opts, callback) {
        var options = {
            ID: "Alert",
            Title: "",
            Content: "",
            ButtonText: "OK",
            width: 550,
            height: 'auto'
        };
        $.extend(true, options, opts);
        var html = ''
        + '<div id="' + options.ID + '">'
	            + '<p>' + options.Content + '</p>'
        + '</div>';
        $("body").append(html);
        var _dialog = new CDialog({
            dialogClass:options.ID,
            title: options.Title,
            modal: true,
            closeHide: true,
            width: options.width,
            height: options.height,
            buttons: [
                {
                    text: options.ButtonText,
                    click: function () {
                        if (typeof callback == "function")
                            callback();
                        _dialog.Close();
                    }
                }
            ],
            close: function () {
                $("#" + options.ID).remove();
            }
        });
        var container = "#" + options.ID;
        _dialog.Init(container);
    },
    Confirm: function (opts, callback) {
        var options = {
            ID: "Alert",
            Title: "",
            Content: "",
            ButtonOK: "OK",
            ButtonCancel: "Cancel",
            width: 550,
            height: 'auto'
        };
        $.extend(true, options, opts);
        var html = ''
        + '<div id="' + options.ID + '">'
	            + '<p>' + options.Content + '</p>'
        + '</div>';
        $("body").append(html);
        var _dialog = new CDialog({
            dialogClass: options.ID,
            title: options.Title,
            modal: true,
            closeHide: true,
            width: options.width,
            height: options.height,
            buttons: [
                {
                    text: options.ButtonCancel,
                    click: function () {
                        if (typeof callback == "function")
                            callback(false);
                        _dialog.Close();
                    }
                },
                {
                    text: options.ButtonOK,
                    click: function () {
                        if (typeof callback == "function")
                            callback(true);
                        _dialog.Close();
                    }
                }
            ],
            close: function () {
                $("#" + options.ID).remove();
            }
        });
        var container = "#" + options.ID;
        _dialog.Init(container);
    }
};